package com.dongjiantong.quarantine.model;

import com.dongjiantong.common.utils.JsonMapper;
import com.dongjiantong.mybatis.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import lombok.Data;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 
 */
@Table(name="djt_breed_reports")
@Data
public class DjtBreedReports extends BaseEntity implements Serializable {

    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();


    /**
     * 养殖场id
     */
    @NotEmpty
    private Long farm_id;

    /**
     * 养殖场名称
     */
    private String farm_name;

    /**
     * 栏舍
     */
    @JsonIgnore
    private String from_stable_json;

    @Transient
    private List<Map<String , Object>> from_stables;

    /**
     * 是否是散户
     */
    private Integer is_scale;

    /**
     * 养殖场地址
     */
    private String farm_address;

    /**
     * 镇
     */
    private String farm_town;

    /**
     * 散户账号
     */
    @JsonIgnore
    private String source_json;
    @Transient
    private List<Map<String , Object>> sources;

    /**
     * 申报号
     */
    private String number;

    /**
     * 申报日期
     */
    @NotEmpty
    private Date date;

    /**
     * 申报人id
     */
    @NotEmpty
    private Long user_id;

    /**
     * 申报人名称
     */
    private String user_name;

    /**
     * 申报人电话
     */
    private String user_mobile;

    /**
     * 货主
     */
    @NotEmpty
    private String owner;

    /**
     * 手机号码
     */
    private String owner_mobile;

    /**
     * 身份证号(收猪人的)
     */
    private String identity_card;

    /**
     * 申报点id
     */
    private Long apply_station_id;

    /**
     * 申报点名称
     */
    private String apply_station_name;

    private Long certificate_station_id;

    private String certificate_station_name;

    /**
     * 养殖类型 1、猪 2、牛 3、羊 4、家禽（申报类型）
     */
    private Integer animal_type;

    private String animal_type_name;

    /**
     * 二级类型
     */
    private Integer animal_second_type;

    private String animal_second_type_name;

    /**
     * 三级类型
     */
    private Integer animal_third_type;

    private String animal_third_type_name;

    /**
     * 动物来源：1:家畜家禽;2:人工饲养;3:合法捕获
     */
    private Integer animal_source;

    /**
     * 野生动物驯养繁殖许可证号
     */
    private String wild_animal_breed_licence;

    /**
     * 野生动物捕捉（猎捕）许可证号
     */
    private String wild_animal_capture_licence;

    /**
     * 用途 1:饲养;2:屠宰;3:展览;4:演出;5:比赛;6:其他
     */
    @NotEmpty
    private Integer purpose_type;

    /**
     * 状态，-1：拒绝， -2：驳回，-3：不发证，0：待提交，1：已提交待处理，2：已受理待勘察，3、已勘察待发证，4：已发证
     */
    @NotEmpty
    private Byte status;

    /**
     * 单位1头 2只 3羽 4克 5 毫升 6 头份 7kg
     */
    @NotEmpty
    private Byte unit;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 发货日期
     */
    @NotEmpty
    private Date deliver_at;

    /**
     * 发货地址
     */
    private String deliver_address;

    /**
     * 屠宰场id
     */
    private Integer butcher_farm_id;

    /**
     * 屠宰场名称
     */
    private String butcher_farm_name;

    /**
     * 收货地编号
     */
    private String receive_code;

    /**
     * 收货地址
     */
    @JsonIgnore
    private String receive_address;

    @Transient
    private Map<String , Object> receive_address_map;

    /**
     *  1 本市  2 本省（去除本市）  3  外省  （1和2 A证 3  B证）
     */
    private Byte is_to_local;

    /**
     * 运输工具号牌
     */
    private String transport_number;

    /**
     * 耳标号
     */
    @Transient
    private List<String> ear_tag_numbers;

    /**
     * 消毒方式
     */
    private String disinfection;

    /**
     * 消毒方式证明号
     */
    private String disinfection_number;

    /**
     * 1  公路
2  水路
3  铁路
4 机动三轮车
5  其它
6  航空
     */
    @NotEmpty
    private Integer transportation;

    /**
     * 到达时间（收货日期）
     */
    @NotEmpty
    private Date receive_at;

    /**
     * 受理人id
     */
    private Long survey_user_id;

    /**
     * 受理人名字
     */
    private String survey_user_name;

    /**
     * 受理人电话
     */
    private String survey_user_mobile;

    /**
     * 处理意见
     */
    private String handle_opinion;

    /**
     * 勘查地点经度
     */
    private String survey_longitude;

    /**
     * 勘查地点纬度
     */
    private String survey_latitude;

    /**
     * 是否经强制免疫并在有效期内
     */
    private Integer is_effective;

    /**
     * 养殖档案是否符合规定
     */
    private Integer is_breeding_archive;

    /**
     * 是否佩戴规定的畜禽标识
     */
    private Integer has_animal_identify;

    private String survey_address;

    /**
     * 养殖场疫情(六个月内)
     */
    private Integer is_epidemic;

    /**
     * 是否在检疫区内
     */
    private Integer is_in_epidemic;

    /**
     * 临床检查
     */
    private Integer examination;

    /**
     * 实验室检测
     */
    private Integer laboratory_test;

    /**
     * 检测结果
     */
    private Integer test_result;

    /**
     * 检疫合格数
     */
    private Integer qualified_quantity;

    /**
     * 检疫合格证编号
     */
    private String quarantine_cert_number;

    /**
     * 检疫不合格数量
     */
    private Integer unqualified_quantity;

    /**
     * 一般处理的数量
     */
    private Integer general_treatment_quantity;

    /**
     * 一般处理的  枚举类型 
     */
    private Integer general_treatment;

    /**
     * 无害化处理的数量
     */
    private Integer harmless_treatment_quantity;

    /**
     * 无害化处理方式
     */
    private Integer harmless_treatment;

    /**
     * 无害化处理ID
     */
    private Long harmless_id;

    /**
     * 无害化处理编号
     */
    private String harmless_number;

    /**
     * 官方兽医id
     */
    private Long vet_user_id;

    /**
     * 官方兽医名称(就是当前登录人)
     */
    private String vet_user_name;

    /**
     * 官方兽医电话
     */
    private String vet_user_mobile;

    /**
     * 备注
     */
    private String remark;

    /**
     * 1：正常，-1：删除
     */
    private Integer delete_flag;

    @NotEmpty
    private Date created_at;

    @NotEmpty
    private Date updated_at;

    private static final long serialVersionUID = 1L;

    public void setFrom_stable_json(String from_stable_json){

        this.from_stable_json = from_stable_json;

        if(Strings.isNullOrEmpty(from_stable_json)){
            this.from_stables = null;
        }else {
            try {
                this.from_stables = objectMapper.readValue(from_stable_json, new TypeReference<List<Map<String , Object>>>() {});
            } catch (IOException e) {
                //ignore this fucking exception
            }
        }
    }


    public void setFrom_stables(List<Map<String , Object>> from_stables){

        this.from_stables = from_stables;

        if(from_stables == null || from_stables.isEmpty()){
            this.from_stable_json = null;
        }else {
            try {
                this.from_stable_json = objectMapper.writeValueAsString(from_stables);
            } catch (JsonProcessingException e) {
                //ignore this fucking exception
            }
        }
    }

    public void setSource_json(String source_json){

        this.source_json = source_json;

        if(Strings.isNullOrEmpty(source_json)){
            this.sources = null;
        }else {
            try {
                this.sources = objectMapper.readValue(source_json, new TypeReference<List<Map<String , Object>>>() {});
            } catch (IOException e) {
                //ignore this fucking exception
            }
        }
    }

    public void setSources(List<Map<String , Object>> sources){
        this.sources = sources;

        if(sources == null || sources.isEmpty()){
            this.source_json = null;
        }else {
            try {
                this.source_json = objectMapper.writeValueAsString(sources);
            } catch (JsonProcessingException e) {
                //ignore this fucking exception
            }
        }
    }


    public void setReceive_address(String receive_address){
        this.receive_address = receive_address;

        if(!Strings.isNullOrEmpty(receive_address)){
            this.receive_address_map = null;
        }else {
            try {
                this.receive_address_map = objectMapper.readValue(receive_address, new TypeReference<Map<String , Object>>() {});
            } catch (IOException e) {
                //ignore this fucking exception
            }
        }
    }

    public void setReceive_address_map(Map<String , Object> receive_address_map){
        this.receive_address_map = receive_address_map;

        if(receive_address_map == null || receive_address_map.isEmpty()){
            this.receive_address = null;
        }else {
            try {
                this.receive_address = objectMapper.writeValueAsString(receive_address_map);
            } catch (JsonProcessingException e) {
                //ignore this fucking exception
            }
        }
    }

    /**
     * 勘察照片
     */
    @Transient
    private List<String> site_survey_photo_list;


    /**
     * 检疫合格证的图片
     */
    @Transient
    private List<String> quarantine_cert_photo_list;

}